const parser = require('@babel/parser');
const { default: generate } = require('@babel/generator'); // 使用解构赋值获取默认导出
const fs = require('fs');
const path = require('path');

try {
  const filePath = path.resolve(__dirname, 'index.js');
  const code = fs.readFileSync(filePath, 'utf-8');
  let ast = parser.parse(code);

  // 如果你想查看 AST，可以取消下面这行的注释
  // console.log(JSON.stringify(ast, null, 2));

  const { code: output } = generate(ast);
  console.log(output);
} catch (error) {
  console.error('An error occurred:', error.message);
}